#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <assert.h>
using namespace std;

void* myMemcpy(void* dest, void* src, size_t sz)
{
	void* ret = dest;

	assert(dest != nullptr);
	assert(src != nullptr);

	for(int i = 0; i < sz; i++)
	{
		*(char*)dest = *(char*)src;
		dest = (char*)dest + 1;
		src = (char*)src + 1;
	}
	return ret;
}

void* myMemmove(void* dest, void* src, size_t sz)
{
	char* p1 = (char*)dest;
	char* p2 = (char*)src;
	assert(dest);
	assert(src);
	if (p1 < p2)
	{
		for (int i = 0; i < sz; i++)
		{
			//*(char*)p1 = *(char*)p2;
			//p1 = (char*)p1 + 1;
			//p2 = (char*)p2 + 1;
			*(p1++) = (*p2++);
		}
	}
	else
	{
		p1 = p1 + sz -1;
		p2 = p2 + sz -1;
		for (int i = 0; i < sz; i++)
		{
			*(p1--) = (*p2--);
		}
	}
	return dest;
}

int main()
{
	int arr[5] = {0,1,2,3,4};
	int* arr1 = new int[5];
	//myMemcpy(arr1,arr,sizeof(arr));
	//for (int i = 0; i < 5; i++)
	//{
	//	cout << arr1[i] << endl;
	//}
	myMemmove(arr1, arr, sizeof(arr));
	for (int i = 0; i < 5; i++)
	{
		cout << arr1[i] << endl;
	}

	delete[] arr1;
	return 0;
}